package com.hxzy.springbootrabbitmqproducer.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Routing路由模型
 * 一个交换机exchange 可以绑定多个队列
 *
 * @author admin
 * @date 2021-07-22
 * finished
 */
@Configuration
public class DirectExchangeConfig {


    /**
     * 消息队列模型交换机
     * @return
     * springframework.amqp.core-->DirectExchange 重定交换
     */
    @Bean
    public DirectExchange directExchange(){

        return new DirectExchange("shop.direct");
    }

    /**
     *  hxzy_email队列绑定给交换机
     * @param mobileQueue
     * @param directExchange
     * @return binding
     */
    @Bean
    public Binding directExchangeBindEmailQueue(Queue mobileQueue,DirectExchange directExchange){
        return BindingBuilder.bind(mobileQueue).to(directExchange).with("mobile");
    }

    /**
     *  hxzy_mobile队列绑定给交换机
     * @param emailQueue
     * @param directExchange
     * @return
     */
    @Bean
    public Binding directExchangeBindMobileQueue(Queue emailQueue,DirectExchange directExchange){
        return BindingBuilder.bind(emailQueue).to(directExchange).with("email");
    }


}
